Skip to content

v11 spec-first playground: Pratt parser + §10.10 simplifier#240

Draft
dkryaklin wants to merge 1 commit intopostcss:masterfrom
dkryaklin:v11/spec-first-playground
Draft

v11 spec-first playground: Pratt parser + §10.10 simplifier#240
dkryaklin wants to merge 1 commit intopostcss:masterfrom
dkryaklin:v11/spec-first-playground

Conversation

@dkryaklin
Copy link
Copy Markdown

@dkryaklin dkryaklin commented Apr 22, 2026

What

A decoupled prototype of new calc() internals under playground/pratt/

Why

v10 uses a JISON-generated LR parser and an ad-hoc reducer. It doesn't cover min() / max() / clamp(), typed division (calc(100vw / 1px)), or calc-keyword folding (pi, e, infinity). CSS Values & Units 4 §10 gives a deterministic simplification algorithm — implementing it directly makes correctness reviewable section-by-section rather than invented-and-patched.

How

Five TS modules, each mapped one-to-one to a spec section:

  • tokenizer.ts — §10.1 tokens
  • parser.ts — §10.1 grammar (Pratt + parselet registry)
  • type.ts — §10.2 calculation types
  • simplify.ts — §10.10 simplification
  • serialize.ts — §10.12 output

169 tests (parser / tokenizer / simplify / typed / opaque / serialize / WPT crib), run via pnpm test:pratt. tsx runtime, no build step.

See ROADMAP.md for more details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant